package net.findkrypton.entity;

import java.util.List;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import net.findkrypton.enume.LoopStateEnum;
import net.findkrypton.event.HelpStateEvent;
import net.jumpengine.Manager;
import net.jumpengine.bean.ChangeBase;

public class LoopUpdateBase extends ChangeBase{
	private HelpStateEvent helpStateEvent;
	private List<Image> list;
	int num=0,len=0;

	public LoopUpdateBase(int x, int y, int interval, List<Image> list, HelpStateEvent helpStateEvent) {
		super(interval);
		this.list=list;
		this.helpStateEvent=helpStateEvent;
	}

	@Override
	protected void invoke() {
		num++;
		helpStateEvent.getNumBase().setText(num+"");

		if(num>3) {
			num=0;
			helpStateEvent.getNumberBox().get(len).setState(LoopStateEnum.nomal);
			len++;
			if(len>=list.size())len=0;
			helpStateEvent.getNumberBox().get(len).setState(LoopStateEnum.current);
		}
		
	}

	@Override
	public void draw(GraphicsContext g) {
		g.drawImage(list.get(len), x, y);
	}
	
	public void setLen(int len) {
		if(len>=0 && len<list.size()) {
			helpStateEvent.getNumberBox().get(this.len).setState(LoopStateEnum.nomal);
			this.len=len;
			helpStateEvent.getNumberBox().get(len).setState(LoopStateEnum.nomal);
		}else {
			Manager.getLog().debug("LoopUpdateBase[setLen]len:%d超出范围(0-%d)", len,list.size());
		}
	}
}
